home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / rendering / utilities / lightwave / objchck / copyscene.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1978-06-29  |  15.6 KB  |  462 lines

  1. /*
  2.    CopyScene.rexx
  3.  
  4.    Copyright (C) 1994 Earl C. Terwilliger
  5.                 Phone (606)-723-5718
  6.  
  7.       Internet: AISTERWI@ACS.EKU.EDU
  8.    Conmpuserve: 70575,1330
  9.  
  10.    Non-Commercial USE granted to ALL !!!
  11.  
  12.    One of the problems with giving a LW scene to someone else is 
  13.    that you have to give the other files that are referenced in 
  14.    the scene file and referenced in the object files (such as 
  15.    texture and reflection maps) too. You can easily forget to 
  16.    include a file when copying your scene, image and object files 
  17.    to diskette. Even if you do manage to get all the files, the 
  18.    references to them in the scene and object files may not have 
  19.    the correct drive:directory reference. The person using the 
  20.    scene and objects will have to choose the alternate 
  21.    drive:directory when in LW layout. 
  22.  
  23.    CopyScene.rexx remedies that situation by reading the scene 
  24.    file and copying the referenced files for you. It also, when 
  25.    copying the scene file, modifies the copy to point to the new 
  26.    destination of the copied files. Also copied and modified in 
  27.    this same manner are any object files because of references to 
  28.    texture maps and reflection maps. (The original scene and 
  29.    objects files are not modified, they are only read.) Any images
  30.    referenced by the object files are copied to the destination also.
  31.  
  32.    Syntax: rx CopyScene [drive:directory/]LW-Scene-File [drive:directory] 
  33.  
  34.    Note: The source file parameter must exist (1st parameter) and 
  35.          you must either assign LW: to a drive:directory (which 
  36.          will be used as a default destination if none is specified) 
  37.          or you must specify a second parameter which will be used 
  38.          as the destination Drive:[directory]
  39.  
  40.    Notice that the parameters in [] are optional. The only necessary
  41.    parameter is the scene file name. If you do not specify a destination
  42.    drive:directory (or just drive:) you must assign LW: to a drive
  43.    and/or directory before running the CopyScene script.
  44.  
  45.    Sub-directories are created (if they do not exist) in the destination
  46.    [drive:directory] (or the LW: assigned directory if the destination
  47.    2nd parameter is not specified) for the scene, image and object files.
  48.  
  49.    CopyScene.rexx checks a Lightwave Scene file to make sure that 
  50.    the file names referenced in the scene do indeed exist and are 
  51.    then copied to a destination of your choice. You can first 
  52.    ASSIGN that destination as a drive called LW: as that is what 
  53.    this script file uses as the destination if none is specified. 
  54.    (Or the assignment can be made more permanent in the 
  55.    user-startup Amiga file.) 
  56.    
  57.    For example:
  58.  
  59.        ASSIGN  LW:  WORK:TOASTER/3D
  60.        rx CopyScene DF0:MYSCENE.LWSCN
  61.  
  62.    would copy the myscene.lwscn file from drive DF0: and all 
  63.    files in the DF0: drive/directory structures referenced by the 
  64.    myscene.lwscn file to the proper directories on 
  65.    work:toaster/3d 
  66.  
  67.        ASSIGN  LW: DF0:
  68.        rx CopyScene work:toaster/3d/scenes/my.scene
  69.  
  70.    would copy the my.scene and all its referenced files to the 
  71.    proper directories on the drive DF0: 
  72.  
  73.    Thus it is possible by ASSIGNing the proper destination (LW:) 
  74.    to copy scnenes and files from hard drive to floppy or floppy 
  75.    to hard drive. 
  76.  
  77.    NOTE: If you do not like the LW: assignment and would like to 
  78.    change the destination drive:directory, specify that location 
  79.    as a second parameter and Copyscene will change the default to 
  80.    use it (thus the LW: assignment is not necessary). 
  81.        
  82.        rx CopyScene work:toaster/3d/scenes/my.scene  DF0:
  83.  
  84.    CopyScene.rexx will create any neccessary directories on the 
  85.    ASSIGNed LW: drive (or specified destination path) if they do 
  86.    not exist such as (/IMAGES, /OBJECTS, /SCENES, etc.) 
  87.  
  88.    The NullObject object is also created  automatically in the 
  89.    destination /objects directory.
  90.  
  91.    The scene is also copied in a modified state to the \scenes
  92.    destination. The modified copy of the scene file has the new 
  93.    references to the destination of the copied files. 
  94.  
  95.    An error message is displayed if a file is not found that is 
  96.    referenced by the scene file, however, the CopyScene.rexx 
  97.    script will continue. Some files or file references not found 
  98.    are really OK since they may be references for example to 
  99.    where saved output (RGB images, ANIMs, etc.) will go. (They
  100.    may also not have a drive:destination which LW layout will
  101.    default to load from its supplied /objects,etc. directories
  102.    but will be an error for the CopyScene script.)
  103.  
  104. */
  105.  
  106. /* TRACE(RESULTS) */
  107.  
  108. OPTIONS RESULTS
  109.  
  110. parse arg parm
  111. if arg() = 0 then call syntax()
  112. file = word(parm,1)
  113. if (words(parm) = 2) then dest = word(parm,2)
  114. else                      dest = 'LW:'
  115.  
  116. if (right(dest,1)~= ':') then dest = dest||'/'
  117.  
  118. if ~exists(dest) then call syntax()
  119. if ~exists(file) then call syntax()
  120.  
  121. if (index(file,':') ~= 0) then do
  122.      temp = translate(file,"  ","/:"," ")
  123.      tempwords = words(temp)
  124.      name = word(temp,tempwords)
  125.      source = left(file,length(file)-length(name))
  126. end  
  127. else source = pragma('D')
  128. if (right(source,1) ~= ':') then do
  129.     if (right(source,1) ~= '/') then source = source||'/'
  130. end
  131.  
  132. if ~show('L',"rexxsupport.library") then do
  133.     if addlib('rexxsupport.library',0,-30,0) then
  134.         say "Added rexxsupport.library."
  135.     else do
  136.         say "Error: addlib() of rexxsupport.library failed."
  137.         exit 10
  138.     end
  139. end
  140.  
  141. open('infile',file,'R')
  142. instring=readln('infile')
  143.  
  144. if (pos('LWSC',instring) ~= 1) then do
  145.   close('infile')
  146.   say file' is not a LW scene file!'
  147.   exit(10)
  148. end
  149.  
  150. say
  151. say '[Input  Scene File Name]'file
  152.  
  153. call newdir(dest)
  154. call makenull(dest)
  155.  
  156. temp = translate(file,"  ","/:"," ")
  157. tempwords = words(temp)
  158. nameonly = word(temp,tempwords)
  159. outscn = dest||"scenes/"||nameonly
  160. say '[Output Scene File Name]'outscn
  161.  
  162. open('outfile',outscn,'W')
  163. writeln('outfile',instring)
  164.  
  165. do while eof('infile')=0
  166.      instring = readln('infile')
  167.      lwcmd = word(instring,1)
  168.      c = index(lwcmd,'Load')
  169.      if (index(instring,':') ~= 0) then do
  170.          if (index(instring,'/') ~= 0) then c = c + 1
  171.      end
  172.      if (c > 0) then do
  173.         filename = word(instring,2)
  174.         if (index(instring,':') = 0) then do
  175.             if (left(filename,1) ~= '/') then filename = source||filename
  176.             else filename = source||strip(filename,'L','/')
  177.         end
  178.         temp = upper(translate(filename,"  ","/:"," "))
  179.         c = showlist('A',word(temp,1))
  180.         c = c + showlist('H',word(temp,1))
  181.         if (c = 0) then do
  182.             say instring
  183.             call errmsg('Volume Not Mounted - ERROR')
  184.         end
  185.         else if (~exists(filename)) then do
  186.                  if (upper(word(temp,words(temp))) = "NULLOBJECT") then do
  187.                      say instring '[OK] NullObject already copied.'
  188.                      instring = lwcmd||" "||dest||"/Objects/NullObject"
  189.                  end
  190.                  else do
  191.                       temp = translate(filename,"  ","/:"," ")
  192.                       tempwords = words(temp)
  193.                       name = word(temp,tempwords)
  194.                       objname = source||'objects/'||name
  195.                       if (exists(objname)) then do
  196.                           say filename 'exists as' objname
  197.                           filename = objname
  198.                           call copyfile()
  199.                       end
  200.                       else do
  201.                            say (instring)
  202.                            call errmsg('File Not Found -  ERROR')
  203.                       end
  204.                   end
  205.              end
  206.         else do
  207.             say instring ' [OK]'
  208.             call copyfile()
  209.         end
  210.      end
  211.      writeln('outfile',instring)
  212. end
  213. close('infile')
  214. close('outfile')
  215. say
  216. say '<--- CopyScene Completed -->'
  217. exit 0
  218.  
  219. copyfile: PROCEDURE EXPOSE source dest filename lwcmd instring
  220. OPTIONS RESULTS
  221. temp = translate(filename,"  ","/:"," ")
  222. tempwords = words(temp)
  223. nameonly = word(temp,tempwords)
  224. dir = ""
  225. if (index(lwcmd,"Image")    ~= 0) then dir = 'images/'
  226. if (index(lwcmd,"Texture")  ~= 0) then dir = 'textures/'
  227. if (index(lwcmd,"Object")   ~= 0) then dir = 'objects/'
  228. if (index(lwcmd,"Frame")    ~= 0) then dir = 'frames/'
  229. if (index(lwcmd,"Surface")  ~= 0) then dir = 'surfaces/'
  230. if (dir = "") then do
  231.     say "Unknown LW Scene Command Type -> "lwcmd
  232.     call errmsg('File may not be copied to the proper directory - ERROR')
  233. end
  234. destname = dest||dir||nameonly
  235. instring = lwcmd||' '||destname
  236. if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
  237. else do
  238.     say 'Copying file' filename 'to' destname
  239.     if (~exists(destname)) then do
  240.         address command
  241.         'copy 'filename' 'destname''
  242.         address
  243.         end
  244.     else call errmsg('Copy not done - file already existed - WARNING')
  245. end
  246. return 0
  247.  
  248. call errmsg('Volume Not Mounted - ERROR')
  249.  
  250. newdir: procedure
  251. parse arg DIR
  252. OPTIONS RESULTS
  253. if (exists(DIR||'images')    = 0) then do
  254.   address command
  255.   'makedir 'DIR'images'
  256.   address
  257. end
  258. if (exists(DIR||'objects')   = 0) then do
  259.   address command
  260.   'makedir 'DIR'objects'
  261.   address
  262. end
  263. if (exists(DIR||'frames')    = 0) then do
  264.   address command
  265.   'makedir 'DIR'frames'
  266.    address
  267. end
  268. if (exists(DIR||'textures')  = 0) then do
  269.   address command
  270.   'makedir 'DIR'textures'
  271.   address
  272. end
  273. if (exists(DIR||'surfaces')  = 0) then do
  274.   address command
  275.   'makedir 'DIR'surfaces'
  276.   address
  277. end
  278. if (exists(DIR||'scenes')    = 0) then do
  279.   address command
  280.   'makedir 'DIR'scenes'
  281.    address
  282. end
  283. if (exists(DIR||'motions')   = 0) then do
  284.   address command
  285.   'makedir 'DIR'motions'
  286.    address
  287. end
  288. if (exists(DIR||'previews')  = 0) then do
  289.   address command
  290.   'makedir 'DIR'previews'
  291.    address
  292. end
  293. if (exists(DIR||'bitmaps')   = 0) then do
  294.   address command
  295.   'makedir 'DIR'bitmaps'
  296.    address
  297. end
  298. return 0
  299.  
  300. syntax:
  301. say
  302. say 'Syntax: rx CopyScene [drive:directory/]LW-Scene-File [drive:directory]'
  303. say 
  304. say '  Note: The source file parameter must exist and you must either '
  305. say '        assign LW: to a drive:directory (which will be used as'
  306. say '        a default destination if none is specified) or you must'
  307. say '        specify a second parameter which will be used as the'
  308. say '        destination Drive:[directory]'
  309. say
  310. exit 10
  311.  
  312. makenull: procedure
  313. parse arg DIR
  314. OPTIONS RESULTS
  315. h1 = '46 4f 52 3d 00 00 00 28 4C 57 4F 42 50 4E 54 53'X
  316. h2 = '00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00'X
  317. h3 = '53 52 46 53 00 00 00 00 50 4F 4C 53 00 00 00 00'X
  318. null = h1||h2||h3
  319. open('output',DIR||'objects/'||'NullObject','W')
  320. writech('output',null)
  321. close('output')
  322. return 0
  323.  
  324. readlwob: PROCEDURE EXPOSE source dest destname filename
  325. OPTIONS RESULTS
  326.  
  327. open('lwobfile',filename,'R')
  328. objstring = readch('lwobfile',12)
  329.  
  330. type = substr(objstring,9,4)
  331.  
  332. if (type ~= "LWOB") then do
  333.   close('lwobfile')
  334.   say filename
  335.   call errmsg('This is not a LW Object file! - ERROR')
  336.   return 10
  337. end
  338.  
  339. form   = substr(objstring,1,4)
  340. length = c2d(substr(objstring,5,4),4)
  341. length = length + 8
  342.  
  343. say 'Reading from' filename
  344. /* say 'Object file length is' length 'bytes' */
  345.  
  346. open('lwobout',destname,'W')
  347. say 'Copying to  ' destname
  348. writech('lwobout',objstring)
  349.  
  350. do while eof('lwobfile')=0
  351.     objstring=readch('lwobfile',8)
  352.     if (eof('lwobfile') = 1) then break
  353.     writech('lwobout',objstring)
  354.     chunk  = substr(objstring,1,4)
  355.     length = c2d(substr(objstring,5,4),4)
  356.     /* say 'Chunk Type is' chunk 'with a length of' length 'bytes' */
  357.     if (chunk ~= "SURF") then do
  358.         do while(length>0)
  359. /*
  360.         NOTE: There is a maximum limit to the readch() length which
  361.               is 65535. Therefore if the chunk size is greater than
  362.               this limit, multiple reads are necessary.
  363.                                                                        */
  364.             objstring = readch('lwobfile',length)
  365.             len = length(objstring)
  366.             writech('lwobout',objstring)
  367.             length = length - len
  368.         end
  369.     end
  370.     else do
  371.         objstring = readch('lwobfile',length)
  372.         surfacepos = pos('00'x,objstring,1)
  373.         surface  = substr(objstring,1,(surfacepos-1))
  374.         surfacepos = surfacepos + (surfacepos // 2) + 1
  375.         say 'Surface Name:' surface
  376.         do while (surfacepos < length)
  377.             subchunk = substr(objstring,surfacepos,4)
  378.             /* say 'Subchunk  ' subchunk */
  379.             surfacepos = surfacepos + 4
  380.             len = c2d(substr(objstring,surfacepos,2),4)
  381.             surfacepos = surfacepos + 2
  382.             image = ""
  383.             if (subchunk = "TIMG") then do
  384.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  385.                 say 'Texture Image ->' image
  386.             end
  387.             if (subchunk = 'RIMG') then do
  388.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  389.                 say 'Reflection Image ->' image
  390.             end
  391.             if (image = "(none)") then image = ""
  392.             if (image ~= "") then do
  393.                 if (index(image,':') = 0) then do
  394.                     if (left(image,1) ~= '/') then fullimage = source||image
  395.                     else fullimage = source||strip(image,'L','/')
  396.                 end
  397.                 else fullimage = image
  398.                 temp = translate(fullimage,"  ","/:"," ")
  399.                 tempwords = words(temp)
  400.                 name = word(temp,tempwords)
  401.                 directory = left(fullimage,length(fullimage)-length(name))
  402.                 if (~exists(directory)) then do
  403.                     if (exists(source||"images")) then fullimage = source||'images/'||name
  404.                 end
  405.                 if (index(image,"(sequence)",1) ~= 0) then do
  406.                     temp = translate(image,"  ","/:"," ")
  407.                     tempwords = words(temp)
  408.                     nameonly = word(temp,tempwords-1)
  409.                     destimage = dest||'Images/'||nameonly||' (sequence)'
  410.                     if (len  > length(destimage)) then do
  411.                         objstring = overlay(destimage,objstring,surfacepos,len,'00'x)
  412.                         say image 'overlayed by' destimage
  413.                     end
  414.                     else call errmsg('Image name not Overlayed since new name is longer! - ERROR')
  415.                     destimage = dest||'images/'
  416.                     fullimage = strip(overlay("#?",fullimage,pos("(sequence)",fullimage,1)-1,11,' '),'T')
  417.                     say 'Copying file' fullimage 'to' destimage
  418.                     address command
  419.                     'copy 'fullimage' 'destimage''
  420.                     address
  421.                 end
  422.                 else if (exists(fullimage)) then  do
  423.                     temp = translate(image,"  ","/:"," ")
  424.                     tempwords = words(temp)
  425.                     nameonly = word(temp,tempwords)
  426.                     destimage = dest||'Images/'||nameonly
  427.                     if (len > length(destimage)) then do
  428.                         objstring = overlay(destimage,objstring,surfacepos,len,'00'x)
  429.                         say image 'overlayed by' destimage
  430.                     end
  431.                     else call errmsg('Image name not Overlayed since new name is longer! - ERROR')
  432.                     say 'Copying file' fullimage 'to' destimage
  433.                     if (~exists(destimage)) then do
  434.                         address command
  435.                         'copy 'fullimage' 'destimage''
  436.                         address
  437.                         end
  438.                     else call errmsg('No copy done - File already existed - WARNING')
  439.                 end
  440.                 else do
  441.                      say fullimage
  442.                      call errmsg('File Not Found - ERROR')
  443.                      end
  444.             end
  445.             surfacepos = surfacepos + len
  446.         end
  447.         writech('lwobout',objstring)
  448.     end
  449. end
  450.  
  451. close('lwobfile')
  452. close('lwobout')
  453. return 0
  454.  
  455. errmsg: procedure
  456. parse arg msg
  457. lenmsg = length(msg) - 1
  458. errmsg = '|___________________________________________________________________________'
  459. errmsg = overlay(msg,errmsg,length(errmsg)-lenmsg,lenmsg+1)
  460. say errmsg
  461. return 0
  462.